package com.inventive.jmscache.server;

import javax.jms.*;

/**
 * @author Grant Little <grant.little@coreservices.com.au>
 */
public class JmsCacheTopicSession extends JmsCacheSession implements TopicSession {

    protected boolean transactional = true;
    protected AcknowledgeMode acknowledgeMode = AcknowledgeMode.SESSION_TRANSACTED;

    public JmsCacheTopicSession(JmsCacheServer jmsCacheServer, boolean transactional, int acknowledgmentMode) {
        super(jmsCacheServer);
        this.transactional = transactional;
        if (!transactional) {
            this.acknowledgeMode = AcknowledgeMode.values()[acknowledgmentMode];
        } else {
            this.acknowledgeMode = AcknowledgeMode.SESSION_TRANSACTED;
        }
    }

    public TopicSubscriber createSubscriber(Topic topic) throws JMSException {
        return new JmsCacheTopicSubscriber(this, (JmsCacheDestination)topic);
    }

    public TopicSubscriber createSubscriber(Topic topic, String messageSelector, boolean noLocal) throws JMSException {
        return new JmsCacheTopicSubscriber(this, (JmsCacheDestination)topic, messageSelector, noLocal);
    }

    public TopicPublisher createPublisher(Topic topic) throws JMSException {
        return new JmsCacheTopicPublisher(this, (JmsCacheDestination)topic);
    }
}
